<!DOCTYPE HTML>
<html>
<head>
    <title> 搜索表单</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="csrf-token" content="{{ csrf_token() }}"/>
    <meta name="curr_menu_id" content="{{ $menu_id }}"/>
    <link rel="stylesheet" type="text/css" href="/assets/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/assets/easyui/themes/icon.css" />
    <script type="text/javascript" src="/assets/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/assets/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/assets/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/app.js"></script>
    <script type="text/javascript" src="/js/system/menu.js"></script>
</head>
<body class="easyui-layout" id="layout">
    <div data-options="region:'center'">
        <div id="toolbar">
            {!! $toolBarButton !!}
        </div>
        <table id="listGrid" ></table>
        <div id="form_dialog"></div>
    </div>
    <script>
        $(document).delegate('.btn_set','click',function () {
            var row_id = $(this).attr('row_id');
            $('#layout').layout('remove','east')
            $('#layout').layout('add',{
                region: 'east',
                width: 600,
                title: '菜单按钮设置',
                href:'/sys/menu/setBtn?menu_id='+row_id,
                split: true,
                collapsible:false,
                onCollapse:function () {
//                    $('#layout').layout('remove','east')
                },
                tools: [{
                    iconCls:'icon-save',
                    title:'保存',
                    handler:function(){
                        var checkedItems = $('#list_data').datalist('getChecked');
                        var ids = [];
                        $.each(checkedItems, function(index, item){
                            ids.push(item.id);
                        });
                        if(ids==''){
                            $.messager.alert("提示信息", '你未选择按钮，无法保存', "error");
                        }
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            url: '/sys/menu/saveBtn',
                            type: 'post',
                            data: {
                                ids:ids.join(","),
                                menu_id:row_id
                            },
                            dataType: 'json',
                            success: function (data) {
                                if (data.code == 200) {
                                    $('#list_data').datalist("reload")
                                } else {
                                    $.messager.alert("提示信息", data.data, "error");
                                }
                            }
                        })
                    }
                },{
                    iconCls:'icon-cancel',
                    title:'取消',
                    handler:function(){
                        $('#layout').layout('remove','east')
                    }
                }]
            });


        })
        $(document).delegate('.btn_data','click',function () {
            var row_id = $(this).attr('row_id');
            $('#layout').layout('remove','east')
            $('#layout').layout('add',{
                region: 'east',
                width: 600,
                title: '菜单数据设置',
                href:'/sys/menu/setMenuData?menu_id='+row_id,
                split: true,
                collapsible:false,//这边设置了隐藏伸缩面板的按钮
                onCollapse:function () {
//                    $('#layout').layout('remove','east')
                },
                tools: [{
                    iconCls:'icon-add',
                    title:'添加',
                    handler:function(){
                        $('#form_dialog').dialog({
                            title: '添加菜单数据信息',
                            width: 500,
                            height: 300,
                            left:1200,
                            closed: false,
                            cache: false,
                            draggable:false,
                            href: '/sys/menu/addMenuRule?menu_id='+row_id,
                            modal: true,
                            buttons: [{
                                text: '保存',
                                iconCls: 'icon-ok',
                                handler: function () {
                                    $.ajax({
                                        headers: {
                                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                                        },
                                        url: '/sys/menu/saveMenuRule',
                                        type: 'post',
                                        data: $('#info-form').serialize(),
                                        dataType: 'json',
                                        success: function (data) {
                                            if (data.code == 200) {
                                                $('#list_data').datagrid("reload")
                                                $('#form_dialog').dialog('close');
                                            } else {
                                                $.messager.alert("提示信息", data.data, "error");
                                            }
                                        }
                                    });
                                }
                            }, {
                                text: '取消',
                                iconCls: 'icon-cancel',
                                handler: function () {
                                    $('#form_dialog').dialog('close');
                                }
                            }]
                        });
                    }
                },{
                    iconCls:'icon-cancel',
                    title:'取消',
                    handler:function(){
                        $('#layout').layout('remove','east')
                    }
                }]
            });


        })

    </script>
</body>
</html>
